﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using AleaBelli.Core.Data;
using AleaBelli.Core.AI;

namespace Test
{
    [TestClass]
    public class UnitTestSimpleBattle
    {
        [TestMethod]
        public void TestMoreAttackingDirectionsBattle()
        {
            ReferenceData refdata = ReferenceData.Instance;
            Creator creator = new Creator();

            // british infantry battalion vs german infantry battalion
            Template britishInfTemplate = refdata.GetTemplate(1);
            Template germanInfTemplate = refdata.GetTemplate(2);

            // create an on map 'unit' for each
            AbstractUnit britishInf = creator.CreateUnit(britishInfTemplate, "British");
            Assert.IsNotNull(britishInf);
            AbstractUnit germanInf1 = creator.CreateUnit(germanInfTemplate, "German 1");
            Assert.IsNotNull(germanInf1);
            AbstractUnit germanInf2 = creator.CreateUnit(germanInfTemplate, "German 2");
            Assert.IsNotNull(germanInf2);

            // create a plains hex for the defender
            Hex hex = new Hex()
            {
                TerrainType = TerrainType.Plain,
                X = 0,
                Y = 0,
                Unit = britishInf
            };

            // create a plains hex for the attacker
            Hex hex2 = new Hex()
            {
                TerrainType = TerrainType.Plain,
                X = 1,
                Y = 1,
                Unit = germanInf1
            };

            // create a plains hex for the attacker
            Hex hex3 = new Hex()
            {
                TerrainType = TerrainType.Plain,
                X = 1,
                Y = 1,
                Unit = germanInf2
            };

            // create the battle
            Battle b = new Battle()
            {
                DefendingHex = hex,
                AttackerHex = hex2,
                Tempo = BattleTempo.Probe,
                Complete = false,
                Duration = 0,
                Id = 1,
                Name = "Test Battle - More Attackers"
            };
            b.Supporters.Add(hex3);

            // create the algorthimn
            ICombatAlgorithmn combatAlgo = new SimpleCombatAlgorithmn();

            // fight !
            combatAlgo.FightBattle(b);

        }

        
        [TestMethod]
        public void TestSimpleBattle()
        {
            ReferenceData refdata = ReferenceData.Instance;
            Creator creator = new Creator();

            // british infantry battalion vs german infantry battalion
            Template britishInfTemplate = refdata.GetTemplate(1);
            Template germanInfTemplate = refdata.GetTemplate(2);

            // create an on map 'unit' for each
            AbstractUnit britishInf = creator.CreateUnit(britishInfTemplate, "British");
            Assert.IsNotNull(britishInf);
            AbstractUnit germanInf = creator.CreateUnit(germanInfTemplate, "German");
            Assert.IsNotNull(germanInf);

            // create a plains hex for the defender
            Hex hex = new Hex()
            {
                TerrainType = TerrainType.Plain,
                X = 0,
                Y = 0,
                Unit = britishInf
            };

            // create a plains hex for the attacker
            Hex hex2 = new Hex()
            {
                TerrainType = TerrainType.Plain,
                X = 1,
                Y = 1,
                Unit = germanInf
            };

            // create the battle
            Battle b = new Battle()
            {
                DefendingHex = hex,
                AttackerHex = hex2,
                Tempo = BattleTempo.Probe,
                Complete = false,
                Duration = 0,
                Id = 1,
                Name = "Test Battle - 1 direction"
            };

            // create the algorthimn
            ICombatAlgorithmn combatAlgo = new SimpleCombatAlgorithmn();

            // fight !
            combatAlgo.FightBattle(b);
        }
    }
}
